home *** CD-ROM | disk | FTP | other *** search
Wrap
/* graphics libraries: general library interfaces by Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Josh Horwich, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga Copyright 1987 - 1993 Apple Computer, Inc. All rights reserved. */ #pragma once #ifndef graphicsLibrariesIncludes #define graphicsLibrariesIncludes #ifndef graphicsRoutinesIncludes #include "graphics routines.h" #endif #ifndef mathRoutinesIncludes #include "math routines.h" #endif #ifdef __cplusplus extern "C" { #endif /* We use “if( a ) b; else” instead of “{ if (a ) b; }” because the first one can be used in an if-else statement and the second one can’t (due to the “;” at the end of the macro instance. */ #define NilShapeReturn(a) if ((a) == (gxShape) nil) {GXPostGraphicsError(shape_is_nil); return; } else #define NilShapeReturnNil(a) if ((a) == (gxShape) nil) {GXPostGraphicsError(shape_is_nil); return 0L; } else #define NilStyleReturn(a) if ((a) == (gxStyle) nil) {GXPostGraphicsError(style_is_nil); return; } else #define NilStyleReturnNil(a) if ((a) == (gxStyle) nil) {GXPostGraphicsError(style_is_nil); return 0L; } else #define NilInkReturn(a) if ((a) == (gxInk) nil) {GXPostGraphicsError(ink_is_nil); return; } else #define NilInkReturnNil(a) if ((a) == (gxInk) nil) {GXPostGraphicsError(ink_is_nil); return 0L; } else #define NilTransformReturn(a) if ((a) == (gxTransform) nil) {GXPostGraphicsError(transform_is_nil); return; } else #define NilTransformReturnNil(a) if ((a) == (gxTransform) nil) {GXPostGraphicsError(transform_is_nil); return 0L; } else #define NilColorSetReturn(a) if ((a) == (gxColorSet) nil) {GXPostGraphicsError(colorSet_is_nil); return; } else #define NilColorSetReturnNil(a) if ((a) == (gxColorSet) nil) {GXPostGraphicsError(colorSet_is_nil); return 0L; } else #define NilColorProfileReturn(a) if ((a) == (gxColorProfile) nil) {GXPostGraphicsError(colorProfile_is_nil); return; } else #define NilColorProfileReturnNil(a) if ((a) == (gxColorProfile) nil) {GXPostGraphicsError(colorProfile_is_nil); return 0L; } else #define NilTagReturn(a) if ((a) == (gxTag) nil) {GXPostGraphicsError(tag_is_nil); return; } else #define NilTagReturnNil(a) if ((a) == (gxTag) nil) {GXPostGraphicsError(tag_is_nil); return 0L; } else #ifdef debugging /* just in case the application (or the graphics system) redefined these to something weird... */ #undef DebugStr #undef IfDebug #define IfDebug(a, b) if (a) DebugStr(b); else #define IfDebugReturn(a, b) if (a) { DebugStr(b); return; } else #define IfDebugReturnNil(a, b) if (a) { DebugStr(b); return 0L; } else #define NilParamReturn(a) if ((a) == 0L) {GXPostGraphicsError(parameter_is_nil); return; } else #define NilParamReturnNil(a) if ((a) == 0L) {GXPostGraphicsError(parameter_is_nil); return 0L; } else #define IfErrorReturn(a,b) if (a) { GXPostGraphicsError(b); return; } else #define IfErrorReturnNil(a,b) if (a) { GXPostGraphicsError(b); return 0L; } else #define IfNotice(a, b) if (a) GXPostGraphicsNotice(b); else #define IfWarning(a,b) if (a) GXPostGraphicsWarning(b); else #define IfWarningReturn(a,b) if (a) { GXPostGraphicsWarning(b); return; } else #define IfWarningReturnNil(a,b) if (a) { GXPostGraphicsWarning(b); return 0L; } else #else #define IfDebug(a, b) #define IfDebugReturn(a, b) #define IfDebugReturnNil(a, b) #define NilParamReturn(a) #define NilParamReturnNil(a) #define IfErrorReturn(a,b) #define IfErrorReturnNil(a,b) #define IfNotice(a, b) #define IfWarning(a,b) #define IfWarningReturn(a,b) if (a) return; else #define IfWarningReturnNil(a,b) if (a) return 0L; else #endif enum commonColors { /* common color names */ gxWhite = 1, gxBlack, gxGray, gxGrey = gxGray, #ifndef __QUICKDRAW__ white = 1, black, gray, grey = gray, #endif /* primaries */ red, green, blue, /* secondaries */ cyan, magenta, yellow, /* tertiaries */ orange, chartreuse, aqua, teal = aqua, slate, purple, violet = purple, maroon, /* others */ brown, pink, turquoise, cadmium_lemon, cadmium_light_yellow, aureoline_yellow, naples_deep_yellow, cadmium_yellow, cadmium_deep_yellow, cadmium_orange, cadmium_light_red, cadmium_deep_red, geranium_lake, alizarin_crimson, rose_madder, madder_deep_lake, brown_madder, permanent_red_violet, cobalt_deep_violet, ultramarine_violet, ultramarine_blue, cobalt_blue, royal_blue, cerulean_blue, manganese_blue, indigo, turquoise_blue, emerald_green, permanent_green, viridian_light, cobalt_green, cinnabar_green, sap_green, chromium_oxide_green, terre_verte, yellow_ochre, mars_yellow, raw_sienna, mars_orange, gold_ochre, brown_ochre, deep_ochre, burnt_umber, burnt_sienna, flesh, flesh_ochre, english_red, venetian_red, indian_red, raw_umber, greenish_umber, van_dyck_brown, sepia, warm_grey, cold_grey, ivory_black, lamp_black, titanium_white, zinc_white, pale_gold, gold, old_gold, pink_gold, white_gold, yellow_gold, green_gold, platinum, silver, antique_silver, chrome, steel, copper, antique_copper, oxidized_copper, bronze, brass, iron, rusted_iron, lead, fluorescent_pink, fluorescent_green, fluorescent_blue, incadescent_high, incadescent_low, moonlight, sodium, daylight, dawn, afternoon, dusk, mauve, apple_green, apple_yellow, apple_orange, apple_red, apple_purple, apple_blue, /* common color modifiers */ light = 512, dark = 1024, warm = 2048, reddish = warm, cool = 4096, bluish = cool, grayish = 8192, whitish = light, blackish = dark, greenish = 16384 }; typedef long commonColor; extern gxColorSet commonColorSet; extern gxSetColor commonColorList[]; extern short commonColorCount; /* some very useful constructive definitions for creating colors */ /* see 'color library.c' for an example of their use... */ #define makeRGBSHORT(a,b,c) ((c >> 14) + ((b >> 13) + (a >> 13) << 3) << 3) #define makeCMYKSHORT(a,b,c,d) ((d >> 14) + ((c >> 14) + ((b >> 14) + (a >> 14) << 2) << 2) << 2) #define makeRGB16(a,b,c) ((c >> 11) + ((b >> 11) + (a >> 11) << 5) << 5) #define makeCMYK16(a,b,c,d) ((d >> 12) + ((c >> 12) + ((b >> 12) + (a >> 12) << 4) << 4) << 4) #define xRGB256(a,b,c) {gxRGBSpace,nil,{(a << 8)+a,(b << 8)+b,(c << 8)+c, 0 }} #define xRGB(a,b,c) {gxRGBSpace,nil,{a,b,c,0}} #define xCMYK(a,b,c,d) {gxCMYKSpace,nil,{a,b,c,d}} #define xHSV(a,b,c) {gxHSVSpace,nil,{a,b,c,0}} #define xCIE(a,b,c) {gxCIESpace,nil,{a,b,c,0}} #define xYIQ(a,b,c) {gxYIQSpace,nil,{a,b,c,0}} #define xXYZ(a,b,c) {gxXYZSpace,nil,{a,b,c,0}} #define xLUV(a,b,c) {gxLUVSpace,nil,{a,b,c,0}} #define xLAB(a,b,c) {gxLABSpace,nil,{a,b,c,0}} #define xHLS(a,b,c) {gxHLSSpace,nil,{a,b,c,0}} #define xNTSC(a,b,c) {gxNTSCSpace,nil,{a,b,c,0}} #define xPAL(a,b,c) {gxPALSpace,nil,{a,b,c,0}} #define xGRAY(a) {gxGraySpace,nil,{a,0,0,0}} #define xRGB16(a,b,c) {gxRGB16Space,nil,{makeRGB16(a,b,c),0,0,0}} #define xRGB32(a,b,c) {gxRGB32Space,nil,{(a >> 8),((c >> 8) + (b >> 8) << 8),0,0}} #define xCMYK32(a,b,c,d) {gxCMYK32Space,nil,{((b >> 8) + (a >> 8) << 8),((d >> 8) + (c >> 8) << 8),0,0}} #define sRGB(r,g,b) {r,g,b,0} #define sCMYK(c,m,y,k) {c,m,y,k} #define sRGB256(a,b,c) {(a << 8)+a,(b << 8)+b,(c << 8)+c, 0 } enum commonFaces { gxPlain, gxBold = 1, gxItalic = 2, gxUnderline = 4, gxOutline = 8, gxShadow = 0x10, gxCondense = 0x20, gxExtend = 0x40, gxLighten = 0x80 }; typedef char commonFace; enum commonTransferModes { /* These modes simulate QuickDraw's transfer modes */ commonAddOverMode = 2000, commonSubtractOverMode, commonSubtractPinMode, commonTransparentMode, commonInMode, commonOutMode } ; typedef short commonTransferMode; struct cubic { gxPoint a; gxPoint b; gxPoint c; gxPoint d; } ; struct conic { gxPoint a; gxPoint b; gxPoint c; Fixed lambda; }; #ifndef __cplusplus typedef struct cubic cubic; typedef struct conic conic; #endif /* shape library */ gxShape NewPath(const gxPath *path); gxShape NewPolygon(const gxPolygon *polygon); gxPolygon *GetPolygon(gxShape source, long contour, gxPolygon *polygon); gxPath *GetPath(gxShape source, long contour, gxPath *path); void SetPath(gxShape target, long contour, const gxPath *path); void SetPolygon(gxShape target, long contour, const gxPolygon *polygon); void DrawPolygon(const gxPolygon *polygon, gxShapeFill fill); void DrawPath(const gxPath *path, gxShapeFill fill); void SetShapeIndexPoint(gxShape target, long index, const gxPoint *point); void SetShapeIndexControl(gxShape target, long index, long control); gxPoint *GetShapeIndexPoint(gxShape source, long index, gxPoint *point); long GetShapeIndexControl(gxShape source, long index, long *control); void InsertShape(gxShape target, long index, gxShape toAdd); gxShape ExtractShape(gxShape source, long firstPoint, long numPoints); void AddToShape(gxShape target, gxShape add); void ExtendShape(gxShape target, gxShape add); #ifdef debugging gxShape NewShape2(gxShapeType type, Fixed x, Fixed y); gxShape NewShape4(gxShapeType type, Fixed firstX, Fixed firstY, Fixed lastX, Fixed lastY); gxShape NewShape6(gxShapeType type, Fixed firstX, Fixed firstY, Fixed controlX, Fixed controlY, Fixed lastX, Fixed lastY); void SetShape2(gxShape target, Fixed x, Fixed y); void SetShape4(gxShape target, Fixed firstX, Fixed firstY, Fixed lastX, Fixed lastY); void SetShape6(gxShape target, Fixed firstX, Fixed firstY, Fixed controlX, Fixed controlY, Fixed lastX, Fixed lastY); #else #define NewShape2(type,p1,p2) NewShapeMany(type, (Fixed)p1, (Fixed)p2) #define NewShape4(type,p1,p2, p3, p4) NewShapeMany(type, (Fixed)p1, (Fixed)p2, (Fixed)p3, (Fixed)p4) #define NewShape6(type,p1,p2, p3, p4, p5, p6) NewShapeMany(type, (Fixed)p1, (Fixed)p2, (Fixed)p3, (Fixed)p4, (Fixed)p5, (Fixed)p6) #define SetShape2(source,p1,p2) SetShapeMany(source, (Fixed)p1, (Fixed)p2) #define SetShape4(source,p1,p2, p3, p4) SetShapeMany(source, (Fixed)p1, (Fixed)p2, (Fixed)p3, (Fixed)p4) #define SetShape6(source,p1,p2, p3, p4, p5, p6) SetShapeMany(source, (Fixed)p1, (Fixed)p2, (Fixed)p3, (Fixed)p4, (Fixed)p5, (Fixed)p6) #endif gxShape NewShapeMany(gxShapeType type, Fixed firstArg, ...); void SetShapeMany(gxShape target, Fixed firstArg, ...); gxShape GetBitmapPartsFromFixedBounds(gxShape source, const gxRectangle *bounds); void SetBitmapPartsFromFixedBounds(gxShape target, const gxRectangle *bounds, gxShape bitmapShape); /* arc library, oval library, roundrect library, cubic library, and conic library */ gxShape NewArc(const gxRectangle *rect, Fixed startAng, Fixed sweep, boolean wedge); gxShape NewOval(const gxRectangle *rect); gxShape NewRoundRect(const gxRectangle *rect, const gxPoint *ovalSize); gxShape NewCubic(const cubic *curve); gxShape NewConic(const conic *curve); void DrawArc(const gxRectangle *rect, Fixed startAng, Fixed sweep, boolean wedge); void DrawOval(const gxRectangle *rect, gxShapeFill fill); void DrawRoundRect(const gxRectangle *rect, const gxPoint *ovalSize, gxShapeFill fill); void DrawCubic(const cubic *curve, gxShapeFill fill); void DrawConic(const conic *curve, gxShapeFill fill); void SetArc(gxShape target, const gxRectangle *rect, Fixed startAng, Fixed sweep, boolean wedge); void SetOval(gxShape target, const gxRectangle *rect); void SetRoundRect(gxShape target, const gxRectangle *rect, const gxPoint *ovalSize); void SetCubic(gxShape target, const cubic *curve); void SetConic(gxShape target, const conic *curve); /* graphics debug library */ void SetGraphicsLibraryErrors(void); /* set the error and warning routines */ void SetGraphicsLibraryNotices(void); /* set the notice routine */ char *GraphicsErrorMessage(gxGraphicsError error); char *GraphicsWarningMessage(gxGraphicsWarning warning); char *GraphicsNoticeMessage(gxGraphicsNotice notice); void DisplayGraphicsErrorMessage(gxGraphicsError error, long reference); void DisplayGraphicsWarningMessage(gxGraphicsWarning warning, long reference); void DisplayGraphicsNoticeMessage(gxGraphicsNotice notice, long reference); /* gxShape library */ void CenterShape(gxShape target, gxRectangle *rect); void MoveShapeCenterTo(gxShape target, Fixed x, Fixed y); void RotateShapeAboutCenter(gxShape target, Fixed degrees); void SkewShapeAboutCenter(gxShape target, Fixed xSkew, Fixed ySkew); void ScaleShapeAboutCenter(gxShape target, Fixed hScale, Fixed vScale); /* graphics library */ void MapShapeToSpace(gxShape target, gxViewPort port, gxViewDevice device); void MapShapeFromSpace(gxShape target, gxViewPort port, gxViewDevice device); void MapPointToSpace(gxPoint *target, gxViewPort port, gxViewDevice device); void MapPointFromSpace(gxPoint *target, gxViewPort port, gxViewDevice device); /* gxTransform library */ gxViewPort GetTransformViewPort(gxTransform source); void SetTransformViewPort(gxTransform target, gxViewPort port); void AddToTransformViewPort(gxTransform target, gxViewPort port); void SetShapeViewPort(gxShape target, gxViewPort port); gxViewPort GetShapeViewPort(gxShape source); void SetDeepShapeViewPort(gxShape target, gxViewPort port); void SetDeepShapeViewPorts(gxShape target, long count, const gxViewPort portList[]); void SetDeepShapeTransform(gxShape target, gxTransform); void SetDefaultViewPort(gxViewPort port); gxViewGroup CopyViewGroup(gxViewGroup group); gxTransform ChangeTransformViewGroup(gxTransform target, gxViewGroup oldGroup, gxViewGroup newGroup); gxShape ChangeShapeViewGroup(gxShape source, gxViewGroup oldGroup, gxViewGroup newGroup); gxTransform SeparateShapeTransform(gxShape source); void ReuniteShapeTransform(gxShape target, gxTransform separate); /* graphics state library */ gxStyle SeparateShapeStyle(gxShape source); void ReuniteShapeStyle(gxShape target, gxStyle separate); gxInk SeparateShapeInk(gxShape source); void ReuniteShapeInk(gxShape target, gxInk separate); /* gxShape library */ void GetPathsIndexPointControl(const gxPaths *source, long index, gxPoint **pt, long **controlPtr, long *controlMask); void SetShapeOpenPath(gxShape target); void PreMapTransform(gxTransform source, gxMapping *map); /* graphics library */ #define CopyShape(s) GXCopyToShape(nil,s) #define CopyStyle(s) GXCopyToStyle(nil,s) #define CopyInk(s) GXCopyToInk(nil,s) #define CopyTransform(s) GXCopyToTransform(nil,s) void DisposeTransformAt(gxTransform *target); void DisposeShapeAt(gxShape *target); void DisposeStyleAt(gxStyle *target); void DisposeInkAt(gxInk *target); void DisposeTagAt(gxTag *target); /* gxColor matching library */ gxColorProfile CreateQMSColorProfile(void); gxColorProfile CreateCanonColorProfile(void); gxColorProfile CreateColorSyncSystemProfile(void); /* gxColor library */ void InitCommonColors(void); void DisposeCommonColors(void); void SetShapeRGB(gxShape target, gxColorValue red, gxColorValue green, gxColorValue blue); void SetInkRGB(gxInk target, gxColorValue red, gxColorValue green, gxColorValue blue); void SetShapeHSV(gxShape target, gxColorValue hue, gxColorValue saturation, gxColorValue value); void SetInkHSV(gxInk target, gxColorValue hue, gxColorValue saturation, gxColorValue value); void SetShapeGray(gxShape target, gxColorValue gray); void SetInkGray(gxInk target, gxColorValue gray); /* gxTransferMode library, gxColor library, text library */ void SetShapeCommonTransfer(gxShape target, commonTransferMode mode); void SetShapeCommonColor(gxShape target, commonColor color); void SetShapeCommonFace(gxShape target, commonFace face); void SetInkCommonTransfer(gxInk target, commonTransferMode mode); void SetInkCommonColor(gxInk target, commonColor); void SetStyleCommonFace(gxStyle target, commonFace); commonTransferMode GetInkCommonTransfer(gxInk source); commonColor GetInkCommonColor(gxInk source); commonFace GetStyleCommonFace(gxStyle source); commonTransferMode GetShapeCommonTransfer(gxShape source); commonColor GetShapeCommonColor(gxShape source); commonFace GetShapeCommonFace(gxShape source); gxColor *SetCommonColor(gxColor *target, commonColor color); commonColor GetCommonColor(const gxColor *source); /* gxColor library */ gxColorSpace GetShapeColorSpace(gxShape target); gxColorProfile GetShapeColorProfile(gxShape source); gxColorSet GetShapeColorSet(gxShape source); gxColorSpace GetInkColorSpace(gxInk target); gxColorProfile GetInkColorProfile(gxInk source); gxColorSet GetInkColorSet(gxInk source); void SetShapeColorSpace(gxShape target, gxColorSpace space); void SetShapeColorProfile(gxShape target, gxColorProfile profile); void SetShapeColorSet(gxShape target, gxColorSet set); void SetInkColorSpace(gxInk target, gxColorSpace space); void SetInkColorProfile(gxInk target, gxColorProfile profile); void SetInkColorSet(gxInk target, gxColorSet set); gxColorSet GetViewDeviceColorSet(gxViewDevice source); void SetViewDeviceColorSet(gxViewDevice target, gxColorSet set); gxColorProfile GetViewDeviceColorProfile(gxViewDevice source); void SetViewDeviceColorProfile(gxViewDevice target, gxColorProfile profile); long GetColorSpaceComponents(gxColorSpace space); /* gxTransferMode library */ void InitTransferMode(gxTransferMode *mode); gxTransferMode *SetCommonTransfer(gxTransferMode *transferModeRecord, commonTransferMode mode, unsigned short opValue, const gxColor *opColor); gxColor *TransmogrifyColor(gxColor *dstColor, const gxColor *srcColor, const gxTransferMode *); void SetInkFastXorTransfer(gxInk inky, gxViewDevice destDevice, gxViewPort destViewPort, gxColor *background, gxColor *result); void SetShapeFastXorTransfer(gxShape source, gxColor *background, gxColor *result); gxShape NewCString(const char *cString, const gxPoint *position); gxShape NewPString(const char *pascalString, const gxPoint *position); gxShape NewChar(const char theChar, const gxPoint *position); void SetCString(gxShape target, const char *cString, const gxPoint *position); void SetPString(gxShape target, const char *pascalString, const gxPoint *position); void SetChar(gxShape target, const char theChar, const gxPoint *position); void DrawCString(const char *cString, const gxPoint *position); void DrawPString(const char *pascalString, const gxPoint *position); void gDrawChar(const char theChar, const gxPoint *position); Fixed FixTextWidth(const unsigned char *string, short length); Fixed FixCStringWidth(const char *string); Fixed FixPStringWidth(const char *string); Fixed FixCharWidth(char ch); gxPoint *GetShapeAdvance(gxShape target, gxPoint *advance); void SetGlyphText(gxShape target, const unsigned char *text, long length); void SetGlyphAdvance(gxShape target, const long advanceBits[]); void SetGlyphStyles(gxShape target, const short styleRuns[], const gxStyle glyphStyles[]); long GetGlyphText(gxShape source, unsigned char *text); long GetGlyphAdvance(gxShape source, long advanceBits[]); long GetGlyphStyles(gxShape source, short styleRuns[], gxStyle glyphStyles[]); /* gxMapping library */ void PolyToPolyMap(const gxPolygon *source, const gxPolygon *dest, gxMapping *mapping); /* gxShape library */ void PaintRectangle(const gxRectangle *source, commonColor color); void PaintRectangle2(const gxPoint *leftTop, const gxPoint *rightBottom, commonColor color); void PaintRectangle4(long left, long top, long right, long bottom, commonColor color); /* picture library */ void AddToPicture(gxShape picture, gxShape newShape, gxStyle newStyle, gxInk newInk, gxTransform newTransform); void InsertPictureItem(gxShape picture, long index, gxShape newShape, gxStyle newStyle, gxInk newInk, gxTransform newTransform); gxShape GetPictureItem(gxShape picture, long index, gxShape *destShape, gxStyle *destStyle, gxInk *destInk, gxTransform *destTransform); void SetPictureItem(gxShape picture, long index, gxShape newShape, gxStyle newStyle, gxInk newInk, gxTransform newTransform); /* user library */ void AddShapeUser(gxShape target, const void *data, long length, long type); long GetShapeUser(gxShape source, void *data, long *length, long requestedType, long *foundType, long index); void RemoveShapeUser(gxShape target, long type, long index); /* ramp library */ gxShape NewRamp(const gxColor *firstColor, const gxColor *lastColor, long steps, const gxRectangle *bounds); void DrawRamp(const gxColor *firstColor, const gxColor *lastColor, long steps, const gxRectangle *bounds); gxShape NewCommonRamp(commonColor firstColor, commonColor lastColor, long steps, const gxRectangle *bounds); void DrawCommonRamp(commonColor firstColor, commonColor lastColor, long steps, const gxRectangle *bounds); /* spline library */ #define circleSlack ((fract)0x3504f334) /* if the points form a square, this slop will approximate a circle */ enum { openSpline, closedSpline }; /* passed as the closed parameter */ gxShape MirrorSpline(long count, gxPoint *points, fract slack, boolean closed); /* framing libarary */ void OutsetShape(gxShape source, Fixed distance); void FrameShape(gxShape source, Fixed distance); #ifdef __cplusplus } #endif #endif